<template>
  <Layout>
    <PageHeaderNew :items="items"></PageHeaderNew>
    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">
            <div>
              <form @submit.prevent="rangeform">
                <div class="basic-content">
                  <!-- <div class="form-group">
                    <h4 class="card-title">基础信息</h4>
                  </div> -->
                  <div class="row">
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label for="price" style="display: flex;justify-content: space-between;">
                          <span>真实服务器</span>
                          <span @click="addMachine('/computing/addReal')" class="pointer">+ 创建一台真机</span>
                        </label>
                        <multiselect
                          v-model="value1"
                          :options="options"
                          placeholder="请选择一台真实服务器"
                          :class="{
                            'is-invalid': submit && $v.value1.$error,
                          }"
                        ></multiselect>
                        <div v-if="submit && $v.value1.$error" class="invalid-feedback">
                          <span v-if="!$v.value1.required">该值是必须选择的。</span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label for="price" style="display: flex;justify-content: space-between;">
                          <span>虚拟服务器</span>
                          <span @click="addMachine('/computing/addFictitious')" class="pointer">+ 创建一台虚机</span>
                        </label>
                        <multiselect
                          v-model="value2"
                          :options="options2"
                          placeholder="请选择一台虚拟服务器"
                          :class="{
                            'is-invalid': submit && $v.value2.$error,
                          }"
                        ></multiselect>
                        <div v-if="submit && $v.value2.$error" class="invalid-feedback">
                          <span v-if="!$v.value2.required">该值是必须选择的。</span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-4">
                      <div class="form-group">
                        <label for="price">应用服务器端口号</label>
                        <b-form-input
                          for="text"
                          v-model="basicContent.portNum"
                          placeholder="请输入应用服务器端口号"
                        ></b-form-input>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group">
                        <label for="price">应用服务器别名</label>
                        <b-form-input
                          for="text"
                          v-model="basicContent.alias"
                          placeholder="请输入应用服务器别名"
                        ></b-form-input>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group">
                        <label for="price">应用服务器用户/密码</label>
                        <b-form-input
                          for="text"
                          v-model="basicContent.usernamePassword"
                          placeholder="请输入应用服务器用户/密码"
                        ></b-form-input>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label for="price">应用程序安装路径</label>
                        <b-form-input
                          for="text"
                          v-model="basicContent.installationPath"
                          placeholder="请输入应用程序安装路径"
                        ></b-form-input>
                      </div>
                    </div>
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label for="price">日志输出路径</label>
                        <b-form-input
                          for="text"
                          v-model="basicContent.outputPath"
                          placeholder="请输入日志输出路径"
                        ></b-form-input>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group row">
                        <label class="col-md-1 padding-right col-form-label"
                          >使用用途</label
                        >
                        <div class="col-md-11">
                          <el-checkbox-group v-model="checkList">
                            <el-checkbox label="JEE服务器"></el-checkbox>
                            <el-checkbox label="MySQL"></el-checkbox>
                            <el-checkbox label="ElasticSearch"></el-checkbox>
                            <el-checkbox label="MongoDB"></el-checkbox>
                            <el-checkbox label="ClickHouse"></el-checkbox>
                            <el-checkbox label="Redis"></el-checkbox>
                            <el-checkbox label="kafka"></el-checkbox>
                            <el-checkbox label="中间件"></el-checkbox>
                            <el-checkbox label="Jar服务"></el-checkbox>
                            <el-checkbox label="vmware"></el-checkbox>
                          </el-checkbox-group>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-12">
                      <div class="form-group row">
                        <label class="col-md-1 padding-right col-form-label"
                          >计算环境</label
                        >
                        <div class="col-md-11">
                          <el-radio v-model="radio" label="1">测试环境</el-radio>
                          <el-radio v-model="radio" label="2">正式环境</el-radio>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label for="productdesc">备注</label>
                    <textarea
                      v-model="extendInfo.textarea"
                      class="form-control"
                      name="textarea"
                      rows="6"
                      placeholder="请输入相关备注信息"
                    ></textarea>
                  </div>
                </div>
                <div class="form-group mb-0">
                  <div style="width: 400px; margin: 0 auto">
                    <b-button
                      type="submit"
                      class="btn btn-primary"
                      variant="success"
                      @click="makeToast('success')"
                      >开始检测</b-button
                    >
                    <button type="submit" @click="todetail" class="btn btn-primary" style="float: right">
                      添加资源
                    </button>
                  </div>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title="检测结果"
      :visible.sync="centerDialogVisible"
      top="15%"
      width="30%"
      :show-close="false"
      center>
      <div style="text-align:center;">
        <p>该计算资源尚未部署代理检测程序</p>
        <p>通知系统管理员 wangyi@stonedt.com 添加该资源</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </Layout>
</template>

<script>
import Layout from "../../layouts/main";
import PageHeaderNew from "@/components/page-header-new";
import { required, minLength } from "vuelidate/lib/validators";
import Multiselect from "vue-multiselect";
export default {
  validations: {
    basicContent: {
      name: { required, minLength: minLength(6) },
      address: { required },
    },
    value1: { required },
    value2: { required },
  },
  components: {
    Layout,
    PageHeaderNew,
    Multiselect,
  },
  data() {
    return {
      items: [
        {
          text: "计算资源",
          url: "/computing",
        },{
          text: "添加应用服务器监控",
          url: "/",
        }
      ],
      submit: false,
      // 下拉框选项
      options: ["真实服务器"],
      options2: ["虚拟服务器"],
      value1: null,
      value2: null,
      extendInfo: {
        textarea: "",
      },
      // 基本信息
      basicContent: {
        name: "",
        address: "",
        portNum: "",
        alias: "",
        usernamePassword: "",
        installationPath: "",
        outputPath: "",
      },
      checkList: ["JEE服务器","MySQL","ElasticSearch","MongoDB","ClickHouse","Redis","kafka","中间件","Jar服务","vmware"],
      radio: '1',
      centerDialogVisible: false,
    };
  },
  methods: {
    rangeform() {
      this.submit = true;
      this.$v.$touch();
    },
    makeToast(variant = null) {
      this.centerDialogVisible = true
      // this.$bvToast.toast("Toast body content", {
      //   title: `Toast ${variant || "default"}`,
      //   variant: variant,
      //   solid: true,
      // });
      console.log(variant);
    },
    todetail(){
      this.$router.push('/computing')
    },
    addMachine(url){
      this.$router.push(url)
    },
  }
};
</script>

<style lang="scss" scoped>
.card-body ::v-deep .newul{
  display: block;
  li{
    display: inline-block;
    margin: 0 1rem;
    a{
      padding: 0.5rem 0rem;
    }
  }
}
label{
  font-weight: normal;
}
.padding-right {
  padding-right: 0;
  padding-top: 0rem;
  padding-bottom: 0.2rem;
}
::v-deep .el-checkbox__input.is-checked .el-checkbox__inner,
::v-deep .el-checkbox__input.is-indeterminate .el-checkbox__inner,
::v-deep .el-radio__input.is-checked .el-radio__inner{
  background-color: #5664d2;
  border-color: #5664d2;
}
::v-deep .el-checkbox__input.is-checked+.el-checkbox__label,
::v-deep .el-radio__input.is-checked+.el-radio__label{
  color: #5664d2;
}
</style>